<template>
  <div class="radioButtonBarPage ls-panel">
    <div class="ls-flex radioButtonBar">
      <div v-for="item in buttons" :key="item.name" class="ls-text-hover" :class="{selected:item.selected}"
           @click="selectButton(item)">
        {{ item.name }}
      </div>
    </div>
  </div>
  <transition enter-active-class="animate__animated animate__fadeInRight animate__faster"
              leave-active-class="animate__animated animate__fadeOutRight animate__faster" mode="out-in">
    <!--如果需要每次切换面板后重新渲染，可以去掉keep-alive-->
    <keep-alive>
      <component :is="selectedPanel" :radioButton="selectedButton"></component>
    </keep-alive>
  </transition>
</template>

<script lang="ts">
import {defineComponent} from 'vue';
import setupRadioButtonPanel, {RadioButtonType} from "./radioButtonPanelCore";
import radioButtonPanelTestA from "./radioButtonPanel/radioButtonPanelTestA.vue";
import radioButtonPanelTestB from "./radioButtonPanel/radioButtonPanelTestB.vue";

export default defineComponent({
  name: 'radioButtonPanelShell',
  setup() {
    const {
      buttons, selectedButton, selectedPanel, selectButton
    } = setupRadioButtonPanel<RadioButtonType>([
      {
        name: '按钮1',
        selected: false,
      },
      {
        name: '按钮2',
        selected: false,
      }
    ], [
      radioButtonPanelTestA,
      radioButtonPanelTestB
    ]);

    return {
      buttons, selectedButton, selectedPanel, selectButton
    };
  }
})
</script>

<style scoped>
.radioButtonBarPage {
  position: absolute;
  right: 0.5em;
  top: 0.5em
}

.radioButtonBar > div {
  border-right: var(--el-border-base);
  padding: 0.5em
}

.radioButtonBar > div:last-child {
  border-right: none;
}

.ls-text-hover.selected {
  color: var(--el-color-primary-light-2);
}

.ls-text-hover.selected:hover {
  color: var(--el-color-primary);
}
</style>